package com.leihao.marketing.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leihao.common.core.exception.ServiceException;
import com.leihao.common.core.utils.StringUtils;
import com.leihao.marketing.domain.ListRequest;
import com.leihao.marketing.domain.Subject;
import com.leihao.marketing.mapper.SubjectMapper;
import com.leihao.marketing.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubjectServiceImpl implements SubjectService {
    @Autowired
    private SubjectMapper subjectMapper;
    @Override
    public void add(Subject subject) {
        subjectMapper.add(subject);
    }

    @Override
    public void delete(Integer subjectId) {
            if (subjectId == null){
                throw new ServiceException("删除编号不能为空!");
            }
            subjectMapper.delete(subjectId);
    }

    @Override
    public PageInfo<Subject> findList(ListRequest listRequest) {
        PageHelper.startPage(listRequest.getPageNum(),listRequest.getPageSize());
        List<Subject> list = subjectMapper.findList();
        PageInfo<Subject> subjectPageInfo = new PageInfo(list);
        return subjectPageInfo;
    }

    @Override
    public Subject findById(Integer subjectId) {
        if (subjectId == null){
            throw new ServiceException("查询编号不能为空!");
        }
        return subjectMapper.findById(subjectId);
    }

    @Override
    public void update(Subject subject) {
        if (subject.getSubjectId() == null){
            throw new ServiceException("修改编号不能为空!");
        }
        subjectMapper.update(subject);
    }

    @Override
    public List<Subject> findAll() {
        return subjectMapper.findAll();
    }
}
